<!-- 积分专区首页 -->
<template>
	<view class="container">
		<view class="header">
			<!-- #ifdef MP-WEIXIN -->
			<view class="navBar" :style="{paddingTop:MenuButtonTop - 6 + 'px'}">
			<!-- #endif -->
			<!-- #ifndef MP-WEIXIN -->
			<view class="navBar">
			<!-- #endif -->
				<view class="navBarLeft" @tap="goBack">
					<text class="yticon icon-zuo"></text>
					<text class="title">VIP积分商城</text>
				</view>
				<!-- #ifndef MP-WEIXIN -->
				<view class="navBarRight" @tap="navTo('/mall/IntegralMall/IntegralOrder')">
					<text class="title">兑换订单</text>
				</view>
				<!-- #endif -->
			</view>
			<view class="searchBox">
				<view class="search">
					<icon class="searchIcon" type="search" :size='20' color='#999'></icon>
					<input class="searchInp" type="text" confirm-type="search" v-model="keyword" placeholder="请输入商品名称" @confirm="search" />
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<view class="navBarRight" @tap="navTo('/mall/IntegralMall/IntegralOrder')">
					<text class="title">兑换订单</text>
				</view>
				<!-- #endif -->
			</view>
			<view class="cateBox">
				<view class="cateList">
					<scroll-view class="scroll__view" scroll-x="true">
						<view class="list">
							<block v-for="(item,index) in data.cate_list" :key="index">
								<view class="item" @click="clickCate(index,item.cate_id)">
									<view :class="active === index?'active':''" class="item-text">
										{{item.cate_name}}
									</view>
								</view>
							</block>
							<block>
								<view class="item cut">
									<view class="item-text">
										1
									</view>
								</view>
							</block>
						</view>
					</scroll-view>
				</view>
				<view class="cate" @tap="navTo('/mall/IntegralMall/IntegralCate')">
					<image src="../static/images/1dsfsa.png" mode=""></image>
					<text>分类</text>
				</view>
			</view>
		</view>
		<!-- 轮播 -->
		<view class="carousel-section">
			<swiper class="carousel" circular autoplay :indicator-dots="true" indicator-color="rgba(255,255,255,.5)"
			 indicator-active-color="#ffffff">
				<swiper-item v-for="(item, index) in data.banner" :key="index" class="carousel-item" @click="navTo(item.ad_link)">
					<image class="carousel-image" lazy-load :src="item.ad_code" />
				</swiper-item>
			</swiper>
		</view>
		
		<view class="goods-list">
			<view class="cardInfoMin">
				<text class="a">当前积分</text>
				<view class="title">
					<image src="../../static/images/center/1qdwdqd.png" mode=""></image>
					<text>{{Number(data.integral)}}</text>
				</view>
			</view>
			<empty v-if="empty" :custom="true" src="/mall/static/images/no-goods.png" text="无相关商品"></empty>
			<goods-block :goodsList="goodsList" :integral="true" :scrollTop="scrollTop"></goods-block>
			<uni-load-more class="loadMore" iconType="circle" :status="loadStatus" :contentText="contentText"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import empty from "@/components/empty/empty";
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import goodsBlock from "@/components/goodsBlock/goodsBlock.vue"
	import {
		signShopList,
		signShopBasic
	} from '@/api/mall.js'
	export default {
		components: {
			uniLoadMore,
			goodsBlock,
			empty
		},
		data() {
			return {
				//#ifdef MP-WEIXIN
				MenuButtonTop: getApp().globalData.MenuButtonTop,
				//#endif
				active: 0,
				data: {},
				empty: false,
				loadStatus: "loading",
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多了"
				},
				ordersList: [],
				keyword: '',
				cid: 0,
				page: 1,
				limit: 10,
				goodsList: [],
				scrollTop: 0
			}
		},
		onLoad() {
			signShopBasic().then(res => {
				this.data = res.data
			})
			this.loadData()
		},
		onPageScroll(e) {
			 this.scrollTop = e.scrollTop;
		},
		//加载更多
		onReachBottom() {
			if (this.loadStatus == "more")
				(this.loadStatus = "loading"), this.loadData();
		},
		methods: {
			goBack() {
				uni.navigateBack({
					
				})
			},
			loadData() {
				signShopList({
					page: this.page,
					limit: this.limit,
					search_str: "",
					cate_id: this.cid
				}).then(res => {
					this.loadStatus = "more";
					this.goodsList.push.apply(this.goodsList, res.data);
					if (res.data.length < this.limit) this.loadStatus = "noMore"; //判断所有数据是否加载完成；
					this.page = this.page + 1;
					if (this.goodsList.length == 0) {
						this.empty = true
						this.contentText.contentnomore = ''
					}
				})
			},
			search() {
				uni.navigateTo({
					url: "./IntegralList?keyword=" + this.keyword
				})
			},
			clickCate(index, id) {
				this.active = index
				this.cid = id
				this.loadStatus = "loading";
				this.page = 1;
				this.goodsList = [];
				this.empty = false
				this.loadData()
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.container {
		.header {
			position: sticky;
			left: 0;
			top: 0;
			background: linear-gradient(31deg, #FC7741 0%, #F2913B 100%);
			z-index: 9;
			.navBar{
				height: 44px;
				line-height: 44px;
				//#ifdef APP-PLUS
				padding: var(--status-bar-height) 30rpx 0;
				//#endif
				//#ifdef H5
				padding: 0 30rpx;
				//#endif
				//#ifdef MP-WEIXIN
				padding-left:30rpx;
				padding-right:30rpx;
				//#endif
				display: flex;
				justify-content: space-between;
				.navBarLeft{
					font-size: 36rpx;
					font-weight: bold;
					align-items: center;
					color: #fff;
					.yticon{
						font-weight: normal;
						font-size: 40rpx;
						margin-right: 6rpx;
					}
				}
				.navBarRight{
					display: flex;
					align-items: baseline;
					.title{
						font-size: 32rpx;
						font-weight: 500;
						color: #fff;
					}
				}
			}
			

			.searchBox {
				position: relative;
				padding: 20rpx 30rpx;
				z-index: 3;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.search {
					position: relative;
					flex: 1;

					.searchIcon {
						position: absolute;
						left: 20rpx;
						top: 18rpx;
					}

					.searchInp {
						width: 100%;
						height: 72rpx;
						padding-left: 80rpx;
						font-size: 28rpx;
						box-sizing: border-box;
						background: #FAF9F3;
						border-radius: 36rpx;
					}
				}
				.navBarRight{
					padding-left: 40rpx;
					display: flex;
					align-items: baseline;
					.title{
						font-size: 32rpx;
						font-weight: 500;
						color: #fff;
					}
				}
			}

			.cateBox {
				position: relative;
				z-index: 3;

				.cate {
					position: absolute;
					right: 0;
					top: 10rpx;
					padding: 0 30rpx;
					color: #fff;
					font-weight: bold;
					background: linear-gradient(31deg, #F6883D 0%, #F2913B 100%);
					box-shadow: -10rpx 0 10rpx 3rpx #F6883D;
					height: 90rpx;
					line-height: 90rpx;
					display: flex;
					align-items: center;

					image {
						width: 50rpx;
						height: 50rpx;
					}
				}

				.cateList {
					.scroll__view {
						width: 100%;
					}

					.list {
						display: flex;
						align-items: baseline;

						.item {
							padding: 0 26rpx;
							white-space: nowrap;
							line-height: 100rpx;
							color: #fff;
							font-size: 32rpx;
							text-align: center;

							.item-text {
								min-width: 80rpx;
							}

							.active {
								color: #fff;
								font-size: 40rpx;
								font-weight: bold;
								position: relative;

								&::after {
									position: absolute;
									left: 50%;
									bottom: 10rpx;
									margin-left: -16rpx;
									content: "";
									width: 32rpx;
									height: 4rpx;
									background: #FFFFFF;
									opacity: 0.7;
									border-radius: 2rpx;
								}
							}
						}

						.cut {
							min-width: 140rpx;
							opacity: 0;
						}
					}
				}
			}
		}

		/* 轮播 */
		.carousel-section {
			position: relative;
			z-index: 2;
			margin-top: 30rpx;
			padding: 0 15px;

			.carousel {
				background-color: #fafafa;
				width: 100%;
				border-radius: 30rpx;
				box-sizing: border-box;
				overflow: hidden;
				height: 260rpx;

				.carousel-item {
					width: 100%;
					height: 100%;
					// padding: 0 28rpx;
					overflow: hidden;
				}

				.carousel-image {
					width: 100%;
					height: 100%;
				}
			}
		}
		
		.goods-list {
			padding: 30rpx;
			.cardInfoMin{
				position: fixed;
				left: 0;
				bottom: 500rpx;
				padding: 2rpx 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				height:90rpx;
				background:#FC7741 ;
				border-radius:0px 8rpx 8rpx 0px;
				z-index: 99;
				color: #fff;
				font-weight: bold;
				.title{
					margin-top: 6rpx;
					display: flex;
					align-items: center;
					font-size: 26rpx;
					image{
						width: 26rpx;
						height: 26rpx;
						margin-right: 10rpx;
					}
				}
				.a {
					font-size: 24rpx;
				}
			}
		}
	}

	/deep/.empty-content {
		top: 500rpx !important;
	}
</style>
